package com.skt.casdemo.view;

import java.util.ArrayList;
import java.util.List;

import com.skt.casdemo.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class WebViewActivity extends Activity implements AdapterView.OnItemSelectedListener{
	
	WebView wv;
	Spinner sp;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview_activity);
		
		addItemsOnSpinner();
		
		wv = (WebView)findViewById(R.id.webView1);
		webViewSetting();
		
	}
	
	private void addItemsOnSpinner(){
		sp = (Spinner)findViewById(R.id.spinner1);
		List<String> list = new ArrayList<String>();
		list.add("test.html");
		list.add("game.html");
		list.add("nogame.html");
		list.add("안전 정보");
		
		ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, list);
		sp.setAdapter(dataAdapter);
		sp.setOnItemSelectedListener(this);
	}
	
	private void webViewSetting(){
		if (wv != null){
			//wv.getSettings().setJavaScriptEnabled(true);
			wv.getSettings().setBuiltInZoomControls(true);
			wv.getSettings().setSupportZoom(true);
			wv.getSettings().setUseWideViewPort(true);
			wv.getSettings().setDefaultZoom(ZoomDensity.FAR);
		}
	}
	
	public void onItemSelected(AdapterView<?> parent, View view, int pos,
			long id) {
		// TODO Auto-generated method stub
		Toast.makeText(parent.getContext(), "OnItemSelectedListener : " + parent.getItemIdAtPosition(pos), Toast.LENGTH_SHORT).show();
		if (wv != null){
			
			switch(pos){
			case 0 : // test.html
				wv.loadUrl("http://150.28.70.33:8080/MobileWebTest/test.html");
				break;
				
			case 1 : // game.html
				//wv.loadUrl("http://150.28.70.33:8080/MobileWebTest/game.html");
				wv.loadUrl("http://61.250.22.200:8001/game.html");
				break;
				
			case 2 : // nogame.html
				wv.loadUrl("http://61.250.22.200:8001/nogame.html");
				break;
				
			case 3 : // 안전 정보
				wv.loadUrl("http://1.234.11.32:8080/SafetyInfomation/mapMode.do?latitude=37.5172363&longitude=127.0473248#mapMode");
				
			default :
				break;
			}
		}
	}

	public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub
	}
}
